package com.Service;


import java.lang.reflect.InvocationTargetException;
import java.util.List;

public interface IService<T> {

    /**
     * 根据主键查询实体
     *
     * @param key
     * @return
     */
    T selectByKey(Object key);

    /**
     * 保存实体
     *
     * @param entity
     * @return
     */
    int save(T entity);

    /**
     * 保存实体, 为null的字段不保存
     *
     * @param entity
     * @return
     */
    int saveExcludeNull(T entity);

    /**
     * 更新实体
     *
     * @param entity
     * @return
     */
    int update(T entity);

    /**
     * 更新实体, 为null的字段不更新
     *
     * @param entity
     * @return
     */
    int updateExcludeNull(T entity);

    /**
     * 删除实体
     *
     * @param entity
     * @return
     */
    int delete(T entity);

    /**
     * 根据主键删除实体
     *
     * @param key
     * @return
     */
    int deleteByKey(Object key);

    /**
     * 逻辑删除
     *
     * @param entity
     * @return
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    int logicalDelete(T entity) throws IllegalAccessException, InvocationTargetException;

    /**
     * 根据主键逻辑删除
     *
     * @param key
     * @return
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    int logicalDeleteByKey(Object key) throws IllegalAccessException, InvocationTargetException;

    /**
     * 批量保存
     *
     * @param entitys
     * @return
     */
    int batchSave(List<T> entities);

    /**
     * 批量保存
     *
     * @param entitys
     * @param batchSize
     * @return
     */
    int batchSave(List<T> entities, int batchSize);

    /**
     * 批量更新
     *
     * @param entitys
     * @return
     */
    int[] batchUpdate(List<T> entities);

    /**
     * 批量更新，null不更新
     *
     * @param entities
     * @return
     */
    public int batchUpdateExcludeNull(List<T> entities);

    /**
     * 批量删除
     *
     * @param entities
     * @return
     */
    int[] batchDelete(List<T> entities);

    /**
     * 逻辑批量删除
     *
     * @param entities
     * @return
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    int[] batchLogicalDelete(List<T> entities) throws IllegalAccessException, InvocationTargetException;

    /**
     * 根据Example查询列表
     *
     * @param example
     * @return
     */
    List<T> selectByExample(Object example);
}
